home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <gl.h>
- #include <device.h>
- #include <math.h>
- #include <stdio.h>
- #include "defines.h"
- #include "event.h"
- #include "trackball.h"
- #include "rotobj.h"
-
-
- static void add_childrens_center(
- struct node_struct *child,
- Coord total[3],
- int *counter);
-
- static void total_selected_objects(
- struct node_struct *child,
- Coord total[3],
- int *counter);
-
-
-
- extern Matrix view_matrix;
- extern Matrix R_view_matrix;
- extern Matrix identity_matrix;
-
- extern struct node_struct *root;
-
- /* About the window... */
- extern long origin_x, origin_y, size_x, size_y;
-
- /* Mouse values in screen coords */
- static Scoord mx, my;
-
- /* Scaled mouse values (-1.0 to 1.0) */
- static Coord last_x, last_y, new_x, new_y;
-
- static Coord x_axis[3] = {1.0, 0.0, 0.0};
- static Coord rotation_center[3];
-
-
- void rotate_object()
- {
- mx = getvaluator(MOUSEX) - origin_x;
- my = getvaluator(MOUSEY) - origin_y;
-
- /* Scale mouse values to square around -1.0 to 1.0 */
- last_x = 2.0*((Coord)mx/size_x - 0.5);
- last_y = 2.0*((Coord)my/size_y - 0.5);
-
- compute_center(rotation_center);
- }
-
-
- void update_object_rotation(Matrix object_matrix)
- {
- Coord new_euler[4];
- Coord R_euler[4]; /* reversed */
- Matrix new_object_matrix;
-
- mx = getvaluator(MOUSEX) - origin_x;
- my = getvaluator(MOUSEY) - origin_y;
-
- /* Scale mouse values to square around -1.0 to 1.0 */
- new_x = 2.0*((Coord)mx/size_x - 0.5);
- new_y = 2.0*((Coord)my/size_y - 0.5);
-
- axis_to_euler(x_axis, 0.0, new_euler);
- trackball(new_euler, last_x, last_y, new_x, new_y);
-
- last_x = new_x;
- last_y = new_y;
-
- build_rotmatrix(new_object_matrix, new_euler);
-
- loadmatrix(identity_matrix);
-
- translate(rotation_center[0],rotation_center[1],rotation_center[2]);
- multmatrix(R_view_matrix);
- multmatrix(new_object_matrix);
- multmatrix(view_matrix);
- translate(-rotation_center[0],-rotation_center[1],-rotation_center[2]);
-
- getmatrix(object_matrix);
- }
-
-
-
- static void add_childrens_center(
- struct node_struct *child,
- Coord total[3],
- int *counter)
- {
- int s,t,c;
-
- if (child != NULL)
- {
- if (child->node_type == PATCH)
- {
- for (s=0; s<NUMPOINTS; s++)
- for (t=0; t<NUMPOINTS; t++)
- for (c=0; c<3; c++)
- total[c] += child->patch->control[s][t][c];
-
- *counter += NUMPOINTS * NUMPOINTS;
- }
-
- add_childrens_center(child->child, total, counter);
- add_childrens_center(child->sibling, total, counter);
- }
- }
-
-
-
- static void total_selected_objects(
- struct node_struct *child,
- Coord total[3],
- int *counter)
- {
- int s,t,c;
-
- if (child != NULL)
- {
- if (child->selected)
- {
- if (child->node_type == PATCH)
- {
- for (s=0; s<NUMPOINTS; s++)
- for (t=0; t<NUMPOINTS; t++)
- for (c=0; c<3; c++)
- total[c] += child->patch->control[s][t][c];
-
- *counter += NUMPOINTS * NUMPOINTS;
- }
- else
- add_childrens_center(child->child, total, counter);
- }
-
- total_selected_objects(child->sibling, total, counter);
- }
- }
-
-
-
-
- /* Computes the center as the average of all control points of selected
- * objects
- */
- void compute_center(Coord center[3])
- {
- Coord total[3];
- int s,t,c, counter = 0;
-
- total[0] = total[1] = total[2] = (Coord) 0.0;
-
- total_selected_objects(root->child, total, &counter);
-
- if (counter)
- for(c=0; c<3; c++)
- center[c] = total[c]/(Coord)counter;
- }
-
-
-
-
-
-